package com.social.instadownloader.screen.common;

import com.social.instadownloader.R;
import com.social.instadownloader.screen.DownloadScreen;
import com.social.instadownloader.screen.HistoryScreen;
import com.social.instadownloader.screen.HowItWorkScreen;

import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

public class HeaderBarController implements OnClickListener {

	private InstaFragmentScreen mFrag;
	private OnHeaderBarClickListener mListener;
	
	private ImageView imgLeftIcon;
	private ImageView imgRightIcon;
	private TextView tRight;
	private TextView tName;
	
	public HeaderBarController(InstaFragmentScreen frag) {
		mFrag = frag;
	}

	public View onCreateHeaderView(LayoutInflater inflater, ViewGroup container) {
		View v 			= inflater.inflate(R.layout.header_bar, container,false);
		imgLeftIcon 	= (ImageView)v.findViewById(R.id.imgLeftIcon);
		imgRightIcon 	= (ImageView)v.findViewById(R.id.imgRightIcon);
		tName			= (TextView)v.findViewById(R.id.tName);
		tRight			= (TextView)v.findViewById(R.id.tRight);
		imgLeftIcon.setOnClickListener(this);
		imgRightIcon.setOnClickListener(this);
		tName.setText(mFrag.getScreenName());
		tRight.setOnClickListener(this);
		configHeaderBar();
		return v;
	}
	
	private void configHeaderBar(){
		if (mFrag instanceof HowItWorkScreen) {
			
		}else if (mFrag instanceof DownloadScreen) {
			imgLeftIcon.setVisibility(View.GONE);
			imgRightIcon.setVisibility(View.GONE);
		}else if (mFrag instanceof HistoryScreen) {
			imgRightIcon.setVisibility(View.GONE);
//			tRight.setVisibility(View.VISIBLE);
		}
	}
	
	public void setOnHeaderBarClickListener(OnHeaderBarClickListener listener){
		mListener = listener;
	}
	
	public interface OnHeaderBarClickListener{
		public void onLeftIconClick(View v);
		public void onRightIconClick(View v);
		public void onRightTextClick(View v);
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.imgLeftIcon:
			if (mListener!=null) {
				mListener.onLeftIconClick(v);
			}
			break;
		case R.id.imgRightIcon:
			if (mListener!=null) {
				mListener.onRightIconClick(v);
			}
			break;
		case R.id.tRight:
			if (mListener!=null) {
				mListener.onRightTextClick(v);
			}
		default:
			break;
		}
	}
}
